package com.cn.dao;

import com.cn.bean.SimpleMap;

/**
 * FUN: 
 *
 * @author sushy
 * @date 2016-3-23 
 */
public class SqlParam implements java.io.Serializable {
	private static final long serialVersionUID = 1326977494331112562L;
	
	private String tableSuffix = "";
	private StringBuilder paramSql = null;
	private SimpleMap param = null;

	/**
	 * 清空参数
	 */
	public void clearParam() {
		if (paramSql != null) {
			paramSql = null;
		}
		if (param != null) {
			param.clear();
		}
	}

	/**
	 * 清空绑定变量
	 */
	public void cleanVar() {
		if (param != null) {
			param.clear();
		}
	}

	/**
	 * 清空SQL
	 */
	public void clearSql() {
		if (paramSql != null) {
			paramSql = null;
		}
	}

	/**
	 * 增加参数SQL
	 */
	public SqlParam addParamSql(String sql) {
		return addSql(sql);
	}

	/**
	 * 增加参数SQL
	 */
	public SqlParam addSql(String sql) {
		if (paramSql == null) {
			paramSql = new StringBuilder();
		}
		paramSql.append(sql);
		return this;
	}

	/**
	 * 增加绑定变量
	 */
	public SqlParam addParam(SimpleMap param) {
		if (this.param == null) {
			this.param = new SimpleMap();
		}
		this.param.putAll(param);
		return this;
	}

	/**
	 * 增加绑定变量
	 */
	public SqlParam addParam(String name, Object value) {
		if (param == null) {
			param = new SimpleMap();
		}
		if (value == null) {
			param.put(name, "");
		} else {
			param.put(name, value);
		}
		return this;
	}

	/**
	 * 获取查询语句的参数Map
	 * 
	 * @return
	 */
	public SimpleMap getParam() {
		return param;
	}

	/**
	 * 获取查询语句的参数Map
	 * 
	 * @return
	 */
	public String getParamSql() {
		if (paramSql == null) {
			return null;
		}
		return paramSql.toString();
	}

	public String getTableSuffix() {
		return tableSuffix;
	}

	public void setTableSuffix(String tableSuffix) {
		this.tableSuffix = tableSuffix;
	}

	public void setTableSuffix(long id) {
		this.tableSuffix = String.valueOf(id % 10);
	}


}
